\documentclass{scrreprt}

%Imports
\usepackage{listings}
\usepackage{scrhack}
%Commands
\newcommand{\company}{cool-aid.nl}
\newcommand{\product}{tic-tac-toe-app}

\newcommand{\tane}{Tane van Wifferen}
\newcommand{\martijn}{Martijn Verbakel}

\title{Specification for the Tic-Tac-Toe application, by \company}
\author{\martijn, \tane}
\begin{document}
\maketitle
\tableofcontents
\newpage
\chapter{Introduction}
\section{Changelog}
\begin{center}
	\begin{tabular}{| l | l | l | r |}
		\hline
		Name & Date & Version & Comment\\
		\hline
		Tane & 28-03-2014 & 0.1 & Initial Release\\
		\hline
	\end{tabular}
\end{center}

\newpage
\section{Introduction to the product}
This document will give specification for the back-end of the \product . In here, you will find the necessecities to design an application that allows the playing of tic-tac-toe with our servers, through the API that will be described in here. Because it also gives the user the opportunity to hack into our system like this, it is reccomended to keep this document highly secret. This is why this document has a code-black security label, and should not be viewed by anyone other than the business owners of \company. 
\\
\\
The goal of this project is to make a reusable framework for network communication within our server and android- or windows-clients. It will use a tcp-connection, and it would be easy to only need one server-client-engine, for future projects.  
\\
\\
The documentation you will find here will describe the server application of the \product. This is a single program that will run, for users to connect to. The server application will only need to run, with no configuration needed. It will give support for more then one game at a time, as well as a chat-function. 

\chapter{Specification}
\section{Running a Server}
Running a server should be as easy as starting a .jar file from any pc, and placing the ip-adress of the host into either the windows-client, or the android-client. The initial server might be a command line application, but we definetely want to move over to a GUI after some time, this to make it easier for other people to run their own server. 

\section{Interaction with a running server}
The server will have the possibility to run in command-line-mode, so it can run on a headless server. When first run, the app will present a main menu with the following functions:

\begin{enumerate}
	\item Start
		\\
		This starts the server, prints the MOTD, and prints the ip-adress to connect to.
	\item Stop
		\\
		This stops the server.
	\item Print History
		\\
		This prints the last 50 chat messages, this can be helpful for when the NSA knocks on the door. 
	\item Players Online
		\\
		This shows the users that are active now.
	\item configure
		\\
		This is a function that gives configuration options for the server. This includes resetting all of the data in the backend, as well as the location where all the history is saved.
\end{enumerate}

\chapter{Design}
We will start with a command-line-interface, and make a design for the server later.
\\
The program will be run from terminal, and will present the user with the following screen:\\

\begin{lstlisting}[language=bash]
SERVER STATUS: OFFLINE
---------------------------------------------------------------
1. START SERVER
2. VIEW PLAYERS
3. VIEW GAMES
4. CONFIGURE	

ENTER CHOICE:__
\end{lstlisting}

\chapter{Implementation}
\section{Set-up}
The server will save games in a single xml file. There will also be an xml file containing user information, there will only be a user name, and an id-number, this for a functioning chat system. Chat history will be stored in a text file, containing all the necessary tags. 

\section{Protocol}
\paragraph{Server to Client}
The grid will be transmitted using strings. This is an easy starter protocol, and it sends the whole grid in one time. The grid can be represented by a three by three matrix, in wich the squares can have a value. These values can be:\\ \\
\begin{tabular}{|c|c|}
	\hline
	X & 1\\
	\hline
	O & 0\\
	\hline
	empty & -1\\
	\hline
\end{tabular}
\\ \\

Each grid will be preceded by a status integer. This sends the win/loss/tie/still playing status to the client, such that is knows what to do now, and what possibilities are open to the user.\\ 
The following codes will be sent:
\begin{enumerate}
	\item X has won
	\item O has won
	\item X's turn
	\item O's turn
\end{enumerate}
This will make for a ten-digit integer array, which can later be interpreted on the client's side.

\paragraph{client to server}

\end{document}
